package com.sttk.secreconeclick.bookkeep.adapter;

import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;

import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lzb.basic.ProviderMultiAdapter;
import com.sttk.secreconeclick.bookkeep.R;
import com.sttk.secreconeclick.bookkeep.bean.BillBean;
import com.sttk.secreconeclick.bookkeep.bean.YearlyStatisticsBean;

import org.jetbrains.annotations.NotNull;


public class StatisticsAdapter extends ProviderMultiAdapter<YearlyStatisticsBean> {

    public StatisticsAdapter() {
        addItemProvider(new StatisticsItemProvider());
    }

    private class StatisticsItemProvider extends BaseItemProvider<YearlyStatisticsBean> {
        @Override
        public int getItemViewType() {
            return ProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_statistics;
        }

        @Override
        public void convert(@NotNull BaseViewHolder baseViewHolder, YearlyStatisticsBean bean) {
            baseViewHolder.setText(R.id.tvStatisticsItemMonth, bean.getMonth() + context.getString(R.string.month));
            baseViewHolder.setText(R.id.tvStatisticsItemIncome, String.format("%.2f", bean.getIncome()));
            baseViewHolder.setText(R.id.tvStatisticsItemExpenditure, String.format("%.2f", bean.getExpenditure()));
            if (bean.getBalance() >= 0) {
                baseViewHolder.setTextColor(R.id.tvStatisticsItemBalance, Color.parseColor("#00B868"));
                baseViewHolder.setText(R.id.tvStatisticsItemBalance, "+" + String.format("%.2f", bean.getBalance()));
            } else {
                baseViewHolder.setTextColor(R.id.tvStatisticsItemBalance, Color.parseColor("#323433"));
                baseViewHolder.setText(R.id.tvStatisticsItemBalance, String.format("%.2f", bean.getBalance()));
            }
        }
    }
}
